//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace EntLibContrib.Validation.Validators
{
	/// <summary>
	/// Composite RuleSet Validator attribute
	/// </summary>
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true, Inherited = false)]
	public sealed class CompositeRuleSetValidatorAttribute : ValidatorAttribute
	{
		#region Fields
		private string targetRuleSets;
		private ValidationSpecificationSource source;
		private string configurationSourceName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the target ruleSets.
		/// </summary>
		/// <value>The target ruleSets.</value>
		public string TargetRuleSets
		{
			get { return targetRuleSets; }
			set { targetRuleSets = value; }
		}

		/// <summary>
		/// Gets or sets the source.
		/// </summary>
		/// <value>The source.</value>
		public ValidationSpecificationSource Source
		{
			get { return source; }
			set { source = value; }
		}

		/// <summary>
		/// Gets or sets the name of the configuration source.
		/// </summary>
		/// <value>The name of the configuration source.</value>
		public string ConfigurationSourceName
		{
			get { return configurationSourceName; }
			set { configurationSourceName = value; }
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Creates the <see cref="T:Microsoft.Practices.EnterpriseLibrary.Validation.Validator"/> described by the attribute object providing validator specific
		/// information.
		/// </summary>
		/// <param name="targetType">The type of object that will be validated by the validator.</param>
		/// <returns>
		/// The created <see cref="T:Microsoft.Practices.EnterpriseLibrary.Validation.Validator"/>.
		/// </returns>
		/// <remarks>This operation must be overriden by subclasses.</remarks>
		protected override Validator DoCreateValidator(Type targetType)
		{
			return new CompositeRuleSetValidator(
				targetType,
				CompositeRuleSetValidator.GetTargetRuleSets(TargetRuleSets),
				Source,
				ConfigurationSourceName);
		}
		#endregion
	}
}
